/*
 * Copyright 2014 Graham Smith
 */
package uk.co.wobblycogs.vegas.riff;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.file.Path;

/**
 *
 * @author Graham Smith
 */
public class RIFFProjectFactory {

	private static final int BUFFER_SIZE = 1024;
//	public static final byte[] RIFF_TYPE = {(byte) 0x72, (byte) 0x69, (byte) 0x66, (byte) 0x66, (byte) 0x2E, (byte) 0x91, (byte) 0xCF, (byte) 0x11, (byte) 0xA5, (byte) 0xD6, (byte) 0x28, (byte) 0xDB, (byte) 0x04, (byte) 0xC1, (byte) 0x00, (byte) 0x00};
//	public static final byte[] LIST_TYPE = {(byte) 0x6C, (byte) 0x69, (byte) 0x73, (byte) 0x74, (byte) 0x2F, (byte) 0x91, (byte) 0xCF, (byte) 0x11, (byte) 0xA5, (byte) 0xD6, (byte) 0x28, (byte) 0xDB, (byte) 0x04, (byte) 0xC1, (byte) 0x00, (byte) 0x00};

	public RIFFProjectFactory() {
	}

	public RIFFProject load(Path file) throws IOException {
		FileInputStream in = new FileInputStream(file.toFile());
		ByteArrayOutputStream out = new ByteArrayOutputStream(BUFFER_SIZE);
		byte[] tmp = new byte[BUFFER_SIZE];
		while (true) {
			int r = in.read(tmp);
			if (r == -1) {
				break;
			}
			out.write(tmp, 0, r);
		}
		in.close();
		ByteBuffer bb = ByteBuffer.wrap(out.toByteArray());
		bb = bb.order(ByteOrder.LITTLE_ENDIAN);
		RIFFProject p = new RIFFProject();
		p.load(bb);
		return p;
	}

}
